#define DEBUG
#include <cstdio>
#define MAXN 50000
#define MAXLOGN 16

using namespace std;

class Tree {
public:
  int n, m, ind[MAXN+1], to[MAXN*2-1], link[MAXN*2-1], f[MAXN+1], g[MAXN+1], dep[MAXN+1], up[MAXN+1][MAXLOGN+1][3], deg[MAXN+1];
  void init(int n) {
    this->n = n;
    m = 0;
    for (int i=0; i<n; i++) {
      ind[i] = 0;
    }
  }

  void addSide(int u, int v) {
    m++;
    to[m] = v;
    link[m] = ind[u];
    ind[u] = m;
  }

  void initF(int o, int fa=-1) {
    deg[o] = 0;
    f[o] = 0;
    for (int i=ind[o]; i; i=link[i]) {
      deg[o]++;
      if (to[i]!=fa) {
	initF(to[i], o);
	f[o] += f[to[i]];
      }
    }
    if (fa>=0) {
      f[o]+=deg[o];
    } else {
      f[o] = 0;
    }
  }

  void initG(int o, int fa=-1) {
    int sum=0;
    for (int i=ind[o]; i; i=link[i]) {
      if (to[i]!=fa) {
	sum += f[to[i]];
      }
    }
    for (int i=ind[o]; i; i=link[i]) {
      if (to[i]!=fa) {
	g[to[i]] = g[o]+sum-f[to[i]]+deg[o];
	initG(to[i], o);
      }
    }
  }

  void makeDep(int o, int fa=-1) {
    if (fa>=0) {
      dep[o] = dep[fa]+1;
    } else {
      dep[o] = 1;
    }

    for (int i=ind[o]; i; i=link[i]) {
      if (to[i]!=fa) {
	makeDep(to[i], o);
	up[to[i]][0][0] = o;
	up[to[i]][0][1] = f[to[i]];
	up[to[i]][0][2] = g[to[i]];
      }
    }
  }

  void build() {
    initF(0), initG(0);

    makeDep(0);
    up[0][0][0] = -1;
    for (int j=1; j<=MAXLOGN; j++) {
      for (int i=0; i<n; i++) {
	int x=i, y=up[i][j-1][0];
	if (y>=0 && up[y][j-1][0]>=0) {
	  up[i][j][0] = up[y][j-1][0];
	  up[i][j][1] = up[x][j-1][1]+up[y][j-1][1];
	  up[i][j][2] = up[x][j-1][2]+up[y][j-1][2];
	} else {
	  up[i][j][0] = -1;
	}
      }
    }
  }

  int lca(int u, int v) {
    int ret;
    bool revert=false;
    if (dep[u]<dep[v]) {
      revert=true;
      ret=u, u=v, v=ret;
    }
    ret=0;
    for (int i=MAXLOGN; i>=0; i--) {
      if (up[u][i][0]>=0 && dep[up[u][i][0]]>=dep[v]) {
	ret += revert ? up[u][i][2] : up[u][i][1];
	u = up[u][i][0];
      }
    }
    if (u==v) {
      return ret;
    }
    for (int i=MAXLOGN; i>=0; i--) {
      if (up[u][i][0]!=up[v][i][0]) {
	ret += revert ? (up[u][i][2]+up[v][i][1]) : (up[u][i][1]+up[v][i][2]);
	u = up[u][i][0], v = up[v][i][0];
      }
    }
    return ret+(revert ? (up[u][0][2]+up[v][0][1]) : (up[u][0][1]+up[v][0][2]));
  }
};

int main() {
#ifdef DEBUG
  freopen("4225.in", "r", stdin);
  freopen("4225.out", "w", stdout);
#endif

  static Tree g;
  int test;
  scanf("%d", &test);
  for (int testi=1; testi<=test; testi++) {
    int n;
    scanf("%d", &n);
    g.init(n);
    for (int i=1; i<n; i++) {
      int u, v;
      scanf("%d %d", &u, &v);
      g.addSide(u, v);
      g.addSide(v, u);
    }
    g.build();

    int q;
    scanf("%d ", &q);
    for (int i=1; i<=q; i++) {
      int p;
      scanf("%d", &p);
      int ov, v, ans=0;
      scanf("%d", &ov);
      for (int j=1; j<=p; j++) {
	scanf("%d", &v);
	ans += g.lca(ov, v);
	ov = v;
      }
      printf("%d.0000\n", ans);
    }
    printf("\n");
  }

  fcloseall();
  return 0;
}
